// pages/problemItem/problemItem.js
const app = getApp()
const util = require('../../utils/util.js')
const lbbService = require('../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabNum: '1',
    noHandlerList: [],
    handlerList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.questionName,
    })
    if(options.childId){
        that.setData({
            childId:options.childId
        })
    } else if(options.questionId){
        that.setData({
            id: options.questionId,
            questionName: options.questionName,
            scrollHeight: app.getScrollHeight(47),
        })
    }
    
    if (!!options.hospitalId) {
      that.setData({
        hospitalId: options.hospitalId
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this
    that.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  /** 
   * 预览图片
   */
  previewImage: function (e) {
    var urls = e.target.dataset.src;
    wx.previewImage({
      urls: urls // 需要预览的图片http链接列表
    })
  },
  toggleTab: function(e) {
    console.log(e)
    let tabNum = e.currentTarget.dataset.num
    this.setData({
      tabNum
    })
  },
  getList: function() {
    let that = this
    let hospitalId = ''
    console.log(that.data)
    if (!!that.data.hospitalId) {
      hospitalId = that.data.hospitalId
    }
    if(that.data.childId) {
        lbbService.getProblems({
            childId: parseInt(that.data.childId),
            hospitalId: hospitalId
          },function(res){
            that.setData({
              noHandlerList: res.data.questionPendingList,
              handlerList: res.data.questionProcessedList,
            })
        })
    } else if(that.data.id) {
        lbbService.getProblems({
            typeId: parseInt(that.data.id),
            hospitalId: hospitalId
          },function(res){
            that.setData({
              noHandlerList: res.data.questionPendingList,
              handlerList: res.data.questionProcessedList,
            })
        })
    }
    
  }
})